<?php
/**
 * Created by PhpStorm.
 * User: Bzing
 * Date: 2017/6/27
 * Time: 12:13
 */
namespace app\api\controller;
use app\models\Models;
class Table extends Base {
    /**
     * 选座列表
     * @return \think\response\Json
     */
    public function tableList(){
        if(request()->isPost()){
            $params = input('param.');
            $table = new Models('table');
            try{
                // 登录验证
                self::sign($params);
                $join = [['table_type b','a.type_id = b.id','left']];
                $field = 'a.id,a.name,b.lowest_cost,a.descrip,a.status,a.is_reserve,a.type_id,b.name type_name';
                $list = $table->joinMany($join,['b.bid'=>$params['business_id']],$field);
                foreach($list as $k=>$v){
                    $arr[$v['type_id']][] = $v;
                }
                sort($arr);
            } catch (\Exception $e){
                return json(self::formatResult($e->getCode(),$e->getMessage()));
            }
            return json(self::formatSuccessResult($arr));
        }
    }

    /**
     * 重新选座
     * @return \think\response\Json
     */
    public function reSeat(){
        if(request()->isPost()){
            try{
                // 登录验证
                $params = self::checkLogin(['equipment','encrypt','activity_id','table_id']);
                $activity = new Models('activity');
                $bool = $activity->_save(['id'=>$params['activity_id'],'table_id'=>$params['table_id']]);
                if(!$bool){
                    throw new \LogicException('操作失败',1010);
                }
            } catch (\Exception $e){
                return json(self::formatResult($e->getCode(),$e->getMessage()));
            }
            return json(self::formatSuccessResult(['activity_id'=>$params['activity_id']]));
        }
    }
}